package server

var (
	InternalFile = "internal"

	DomainFile  = "domain"
	ServiceFile = "service"
	UsecaseFile = "usecase"

	DomainPath  = InternalFile + "/" + DomainFile
	ServicePath = InternalFile + "/" + ServiceFile
	UsecasePath = InternalFile + "/" + UsecaseFile
)

// -------------- domain --------------------
var (
	domainTmp = `package domain

import (
	"%s/handler/api"
)

%s

%s
%s
`
	domainStructAddTmp = `
%s

%s
%s
`
	domainStructTmp = `type %s struct {
%s}
`
	strutFieldTmp = "\t%s %s `json:\"%s\"`\n"

	toPbFuncField    = "\t\t%s: d.%s,\n"
	toPbSubFuncField = "\t\t%s: d.%s.ToPb(),\n"
	domainToPbFunc   = `
func (d *%s) ToPb() *api.%s {
	if d == nil {
		return nil
	}

	return &api.%s{
%s	}
}`
	pbToFuncField    = "\t\t%s: pb.%s,\n"
	pbToSubFuncField = "\t\t%s: New%s(pb.%s),\n"
	domainPbToFunc   = `
func New%s(pb *api.%s) *%s {
	if pb == nil {
		return nil
	}

	return &%s{
%s	}
}`
)

// -------------- usecase ------------------

var (
	usecaseTmp = `package usecase

import (
	"context"
	
	"%s/internal/domain"
)

type %sUsecase struct {
	
}

func New%sUsecase() *%sUsecase {
	return &%sUsecase{}
}
`

	usecaseFuncTmp = `
func (s *%sUsecase) %s(ctx context.Context, req *domain.%s) (*domain.%s, error) {
	return &domain.%s{}, nil
}
`
)

// -------------- services ------------------

var (
	serviceTmp = `package service

import (
	"context"

	"%s/handler/api"
	"%s/internal/domain"
	"%s/internal/usecase"
)

type %sService struct {
	api.Unimplemented%sServer

	uc *usecase.%sUsecase
}

func New%sService(uc *usecase.%sUsecase) *%sService {
	return &%sService{uc:uc}
}
`
	serviceFuncTmp = `
func (s *%sService) %s(ctx context.Context, req *api.%s) (*api.%s, error) {
	data, err := s.uc.%s(ctx, domain.New%s(req))
	if err != nil {
		return nil, err
	}

	return data.ToPb(), nil
}`
)
